package com.eight.cloud.admin.facade;

import com.eight.cloud.admin.service.IRoleService;
import com.eight.cloud.admin.service.IUserRoleService;
import com.eight.cloud.admin.entity.UserRoleEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色管理外观模式
 *
 * @ClassName: SysRoleFacade
 * @Author: TXC
 * @Date: 2025-02-19 17:24
 **/
@Service
public class SysRoleFacade {

    @Resource
    IUserRoleService userRoleService;

    @Resource
    IRoleService roleService;

    /**
     * 根据uuid删除角色
     *
     * @param uuid uuid
     */
    public boolean removeRoleByUuid(String uuid) {
        List<UserRoleEntity> rolePermissionList = userRoleService.getUserRoleListByRoleId(uuid);
        if (!rolePermissionList.isEmpty()) {
            throw new RuntimeException("角色已绑定用户，无法删除");
        }
        return roleService.removeByUuid(uuid);
    }
}
